package gwtmodule1.client.gui.stock;

import gwtmodule1.client.gui.utils.DekoTable;
import gwtmodule1.client.gui.utils.FrameClient;
import gwtmodule1.client.gui.utils.HSpacer;
import gwtmodule1.client.gui.utils.Title;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.KeyboardListener;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class PageEditPrices extends VerticalPanel implements FrameClient {

	public class ColorTextBox extends TextBox implements KeyboardListener {

		public ColorTextBox(String val) {
			super();
			addKeyboardListener(this);
			setText(val);
			setTextAlignment(TextBox.ALIGN_RIGHT);
			setWidth("100px");
		}

		public void onKeyDown(Widget sender, char keyCode, int modifiers) {
			setStyleName("ColorTextBoxEdited");
		}

		public void onKeyPress(Widget sender, char keyCode, int modifiers) {

		}

		public void onKeyUp(Widget sender, char keyCode, int modifiers) {

		}

	}

	private class EditPricesTable extends DekoTable {

		public EditPricesTable() {
			super();
			addTitle("Brand");
			addTitle("Product");
			addTitle("Available");
			addTitle("Price (USD)");
			addTitleWidget(new HTML("Normal<br>Discount (%)"));
			addTitleWidget(new HTML("Industrial<br>Discount (%)"));
		}

		public void addItem(int id, String brand, String product,
				int available, float price, int discount, int inddisc) {
			AddRow r = addRow();
			r.add(brand);
			r.add(product);
			r.add(available);
			r.add(new ColorTextBox(price + ""));
			r.add(new ColorTextBox(discount + ""));
			r.add(new ColorTextBox(inddisc + ""));
		}

	}

	public PageEditPrices() {
		super();
		add(new Title("Edit Prices and Discounts"));
		setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		add(new Button("Save Changes"));
		setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
		add(new HSpacer("4px"));
		add(createTable());
	}

	private Widget createTable() {
		EditPricesTable table = new EditPricesTable();
		table.addItem(0, "Microsoft", "XBox", 34, 234.34f, 0, 10);
		table.addItem(1, "Sony", "Playstation 3", 4, 234f, 0, 10);
		table.addItem(2, "Nintendo", "Wii", 44, 23.34f, 10, 15);
		table.addItem(3, "Apple", "iPhone", 554, 234f, 15, 20);
		return table;
	}

	public void onShow(Object param) {
		// TODO Auto-generated method stub

	}

}
